#coding: utf-8
''' This describes the work flow.
'''

import os, sys
sys.path.append("./ExtractDoc/")
sys.path.append("./SegnPOS/py_code")
sys.path.append("./general")
from extractoperations import *
from segnposoperations import *
from generaltools import Debugger


if __name__ == "__main__":
    prefix = "/home/fengys/data/Chinese_Queries_Related_Source_Corpus/data"
    news_cmp = "/home/fengys/data/cmn_gw_5/data"
    web_cmp = "/home/fengys/data//TAC_2012_KBP_Source_Corpus_Additions_Web_Documents/data/cmn"
    news_raw = prefix + '/raw/news'
    web_raw = prefix + '/raw/web'
    news_doc = prefix + '/doc/news'
    web_doc = prefix + '/doc/web'
    query = prefix + '/query'

    argv = [prefix, query, news_cmp, web_cmp, news_raw, web_raw, news_doc, web_doc]

    for i in range(len(sys.argv) - 1):
        argv[i] = sys.argv[i + 1]

    err = {}
    debugger = Debugger(True)
    '''
    (docids, getDocidResult) = getDocidFromQuery(argv[1])
    err['getDocidFromQuery'] = list(getDocidResult)
    f = open('docid', 'w')
    for docid in list(docids):
        f.write(docid + '\n')
    f.close()

    entries = getEntryFromDocid('docid')
    f = open('entry', 'w')
    for entry in list(entries):
        f.write(entry + '\n')
    f.close()


    unzipResult = unzip('entry', news_cmp, web_cmp, news_raw, web_raw)
    err['unzip'] = list(unzipResult)

    normalizeWebResult = normalizeAllXML(web_raw)
    err['normalizeWebXML'] = list(normalizeWebResult)

    normalizeNewsResult = normalizeAllXML(news_raw)
    err['normalizeNewsXML'] = list(normalizeNewsResult)

    createDocResult = createQueryRelatedDoc('entry', 'docid', argv[4], argv[6],  argv[5], argv[7])
    err['createQueryRelatedDoc'] = list(createDocResult)

    repairResult = repairAll(argv[7])
    err['repairAll'] = list(repairResult)
    '''
    parseWebResult = parseAll(argv[7], 'web', 'web')
    err['parseWeb'] = list(parseWebResult)

    parseNewsResult = parseAll(argv[6], 'news', 'news')
    err['parseNews'] = list(parseNewsResult)

    debugger.checkError(err)
